import { reqCategoryList, reqBannerList, reqFloorList } from "@/api"

export default {
  state: {
    categoryList: [],
    bannerList: [],
    floorList: [],
  },
  mutations: {
    //形参（接收到的数据）的名字 categoryList 可以随便取
    UPDATE_CATEGORYLIST(state, categoryList) {
      state.categoryList = categoryList
    },
    UPDATE_BANNERLIST(state, bannerList) {
      state.bannerList = bannerList
    },

    UPDATE_FLOORLIST(state, floorList) {
      state.floorList = floorList
    },
  },
  actions: {
    async getCategoryList({ commit }) {
      const result = await reqCategoryList()
      if (result.code === 200) {
        commit("UPDATE_CATEGORYLIST", result.data.slice(0, 15))
      }
    },
    async getBannerList({ commit }) {
      const result = await reqBannerList()
      // console.log(result, "result")

      if (result.code === 200) {
        commit("UPDATE_BANNERLIST", result.data)
      }
    },

    async getFloorList({ commit }) {
      const result = await reqFloorList()
      // console.log(result, "result")
      if (result.code == 200) {
        commit("UPDATE_FLOORLIST", result.data)
      }
    },
  },
  getters: {},
}
